package com.mainbo.androidframework.persistence.db;

import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;

import com.mainbo.androidframework.App;


/**
 * <b>创建时间</b> 2015-106-04 * create by tools
 */
public class DbHelper extends BaseDbHelper {
    private static final int dbVersion = 1;
    private static DbHelper dbHelper;
    private static String currentEmployeeID;

    private DbHelper(String dbName) {
        super(App.mContext, dbName, null, dbVersion);
    }

    public synchronized static DbHelper getInstance(String targetEmployeeID) {
        if (TextUtils.equals("",targetEmployeeID)) {

            if (dbHelper != null) {
                dbHelper.close();
            }
            if(currentEmployeeID==null){
                currentEmployeeID = "";
            }
        }else {
            if(currentEmployeeID.equals(targetEmployeeID) && dbHelper != null){
                return dbHelper;
            }
            else {
                currentEmployeeID = targetEmployeeID;
                if(dbHelper!=null){
                    dbHelper.close();
                }
            }
        }
        String dbName = currentEmployeeID + ".db";
        dbHelper = new DbHelper(dbName);
        return dbHelper;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }


}